package com.fenghao.subject.common.enums;

import lombok.Getter;

/**
 * 标记删除状态的枚举
 */
@Getter
public enum IsDeletedEnum {

    DELETED(1, "已删除"),
    UN_DELETED(0, "未删除");

    private final int code;
    private final String desc;

    IsDeletedEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    // 通过 code 获取枚举
    public static IsDeletedEnum getEnumByCode(int codeVal) {
        IsDeletedEnum[] isDeletedEnums = IsDeletedEnum.values();
        for (IsDeletedEnum isDeletedEnum : isDeletedEnums) {
            if (isDeletedEnum.code == codeVal) {
                return isDeletedEnum;
            }
        }
        return null;
    }

    // 通过 desc 获取枚举
    public static IsDeletedEnum getEnumByCode(String descVal) {
        IsDeletedEnum[] isDeletedEnums = IsDeletedEnum.values();
        for (IsDeletedEnum isDeletedEnum : isDeletedEnums) {
            if (isDeletedEnum.desc.equals(descVal)) {
                return isDeletedEnum;
            }
        }
        return null;
    }
}
